<script setup>
import { ref } from 'vue'
import axios from 'axios'
// TODO: 编辑

// 弹框开关
const dialogVisible = ref(false)
// 表单数据
const form = ref({})
// 打开弹窗以及回显
const handleOpen = (item) => {
  dialogVisible.value = true
  form.value = item
}


// 编辑保存
const handleSave = async () => {
  // 修改
  await axios.patch(`/edit/${form.value.id}`, {
    name: form.value.name,
    place: form.value.place,
  })
  // 关闭弹窗
  dialogVisible.value = false
}

// 暴露给父组件使用来打开弹窗
defineExpose({ handleOpen })


</script>

<template>
  <el-dialog v-model="dialogVisible" title="编辑" width="400px">
    <el-form label-width="50px">
      <el-form-item label="姓名">
        <el-input placeholder="请输入姓名" v-model="oldData.name" />
      </el-form-item>
      <el-form-item label="籍贯">
        <el-input placeholder="请输入籍贯" v-model="oldData.place" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleSave">确认</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<style scoped>
.el-input {
  width: 290px;
}
</style>
